package flc.ast.widget.calendar;

import android.annotation.SuppressLint;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.graphics.Color;
import android.widget.RemoteViews;

import com.blankj.utilcode.util.TimeUtils;

import java.util.Date;

import flc.ast.R;
import flc.ast.utils.LunarUtils;
import stark.common.basic.utils.BitmapUtil;

public class Calendar3Widget extends BaseCalendarWidget {

    public Calendar3Widget(int appWidgetId) {
        super(appWidgetId);
    }

    @Override
    protected void onUpdate(Context context) {
        @SuppressLint("RemoteViewLayout") RemoteViews remoteViews =
                new RemoteViews(context.getPackageName(), R.layout.widget_calendar3);

        String week = TimeUtils.date2String(new Date(), "E");
        String day = TimeUtils.date2String(new Date(), "dd");
        String date2 = TimeUtils.date2String(new Date(), "yyyy年MM月");
        LunarUtils lunarUtils = new LunarUtils(new Date());
        remoteViews.setImageViewBitmap(R.id.ivCalendar3Date,
                BitmapUtil.text2BmpWithAssetFont(context, date2, Color.WHITE, 15,
                        "font/ziti6.ttf"));
        remoteViews.setImageViewBitmap(R.id.ivCalendar3Day,
                BitmapUtil.text2BmpWithAssetFont(context, day, Color.WHITE, 34,
                        "font/ziti6.ttf"));
        remoteViews.setImageViewBitmap(R.id.ivCalendar3Week,
                BitmapUtil.text2BmpWithAssetFont(context, week, Color.WHITE, 12,
                        "font/ziti6.ttf"));
        remoteViews.setImageViewBitmap(R.id.ivCalendar3Month,
                BitmapUtil.text2BmpWithAssetFont(context, lunarUtils.toString(), Color.WHITE, 12,
                        "font/ziti6.ttf"));

        AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
    }
}
